<template>
  <div class="recommend">
    <p class="title">爱情鲜花</p>
    <div class="line"></div>
    <div class="recommend-content" @click="clickGoods(item.id)" v-for="item in items" :key="item.id">
      <img v-lazy="item.pic" alt="">
      <div class="recommend-right" >
        <p class="name">{{item.name}}</p>
        <p class="desc">{{item.characteristic ? item.characteristic : '暂无描述' | filterDesc}}</p>
        <div class="price">
          <p>&yen;{{item.minPrice}}</p>
          <van-icon @click.stop="addCart(item.id)" name="add-o" size="20" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    items: {
      type: Array,
      requeired: true
    }
  },
  methods: {
    addCart (id) {
      this.$emit('addCart', id)
    },
    clickGoods (id) {
      this.$emit('clickGoods', id)
    }
  },
  filters: {
    filterDesc (val) {
      if (val.length > 10) {
        return val.substr(0, 10) + '...'
      } else {
        return val
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.recommend{
    box-sizing: border-box;
    padding-top: 10px;
    position: relative;
    background-color: #fff;
    .title{
      padding: 15px 0;
      color: #555;
      text-align: center;
      font-weight: bold;
      font-size: 18px;
    }
    .line{
      height: 4px;
      width: 88px;
      background-color: rgb(136,78,34);
      position: absolute;
      top: 50px;
      left: 50%;
      transform: translateX(-50%);
      border-radius: 4px;
    }
    .recommend-content{
      display: flex;
      margin-top: 15px;
      width: 100%;
      img{
        width: 150px;
        height: 150px;
        margin: 0 0 0 10px;
      }
      .recommend-right{
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 0 15px;
        .name{
          margin-top: 10px;
          color: rgb(13, 26, 206);
          font-size: 14px;
          font-weight: bold;
        }
        .desc{
          font-size: 12px;
          margin:40px 0 50px;
        }
        .price{
          display: flex;
          align-items: center;
          >p{
            color: #f43;
            font-weight: bold;
            flex: 1;
          }
          .van-icon-add-o{
            color: red;
          }
        }
      }
    }
}
</style>
